home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
'92_HACK
/
TILEHACK
/
TILEHACK.C
Wrap
C/C++ Source or Header
|
1992-06-18
|
24KB
|
770 lines
/***************************************************************************
TileHack, an FKEY
A Hack that changed, and changed again. This hack is now called
You Got No Fonts, You Skanky Programmer
This hack uses the concept of the FKEY as a way to quickly change
your reality. Think dose, think FKEY.
We actually use NO RESOURCES. This is essential to the self-contained
hack FKEY 'You Got No Fonts, You Skanky Programmer'.
We want a very cool Window, made from the very stuff of code itself,
LetterForm. So we take Outline fonts, make a Picture, turn it into
a RegionHandle with an offscreen port, write it to a resource, turn
the resource into a buncha DC.W's (the skanky programmers friend)
and embed them into the CODE itself ! (like the old days) ALL of
this code is in the FKEY, toggled by a compile-time flag.
When fire off the FKEY, we make a window, invisible, BlockMove the
WDEF code, STUFF the windowProc and leave the scene of the crime.
Don't try this at home, You Skanky Programmer!
B. Marshall Hamlin
Constructor
Noesis Sfwr Construction
ALink: D0781
6300 Leona St
Oakland, CA 94605-1228
***************************************************************************/
// I N C L U D E
//include "LoMem.ph"
#include <LoMem.h>
#include <Resources.h>
#include <Palettes.h>
//*************************************************************************
// F O R W A R D
pascal void FlushCodeCache (void) = 0xA0BD;
pascal long HackWindow (short varCode, WindowPeek theWindow, short message, long param);
void dataProc(void);
void endData(void);
void DrawHackCont(void);
void MakeRgnBg(void);
RgnHandle PICT2Rgn( PicHandle p );
BitMap *PICT2BitMap( PicHandle p );
Boolean CreateOffscreenBitMap(GrafPtr *newOffscreen, Rect *inBounds);
void DestroyOffscreenBitMap(GrafPtr oldOffscreen);
#define kWinHdrHt 98
#define kWinWid 502
#define kWinHt 32 //(407-kWinHdrHt)
//*************************************************************************
// F L A G S
#define NEW_WINDOW 1
#define MAKE_RGN 0
//*************************************************************************
// M A I N
main()
{
SysEnvRec environs;
GrafPtr savPort;
OSErr err;
WindowPeek thWinPtr;
Ptr wdefProcPtr;
Rect bounds;
short off1, off2;
long procSize;
struct { short jmp ;
ProcPtr addr ;} **wdefHdl;
// *************************************************************
// Insert a set of routines to build the Window Region
// Used during development only...
if ( MAKE_RGN) {
MakeRgnBg();
return;
}
// *************************************************************
// Check for color (this is a color-orinted hack!)
err = SysEnvirons( 1, &environs);
if (err != noErr || !environs.hasColorQD)
return;
// *************************************************************
// Decide how big our display window is here
// Should we:
// make it a fixed size?
// search monitors, find a good one, calc size and put it there?
bounds.top = (**GrayRgn).rgnBBox.top + MBarHeight + 2;
bounds.left = (**GrayRgn).rgnBBox.left + 2;
bounds.right = bounds.left + kWinWid;
bounds.bottom = bounds.top + kWinHdrHt; // + kWinHt;
off1 = Random(); off1 = off1 & 0x000f;
off2 = Random(); off2 = off2 & 0x000f;
OffsetRect( &bounds, off1, off2);
// *************************************************************
// Make the window here. Make it invisible, so we can stuff
// the WDEF. We could just pass a WDEF resId, but this is an
// FKEY so we want to keep it _completely_ self-contained.
thWinPtr = NewCWindow( nil, &bounds, "", false, 0, (void*)-1, true, 0L);
procSize = (long)((Ptr)endData - (Ptr)HackWindow); // src dependent
wdefHdl = NewHandle( procSize);
BlockMove( (Ptr)HackWindow, *wdefHdl, procSize);
if (CPUFlag >= 2)
FlushCodeCache();
thWinPtr->windowDefProc = wdefHdl;
GetPort( &savPort);
ShowWindow( thWinPtr);
SetPort( thWinPtr);
// don't need it, we got SOMEBODY's A5
//asm {
// movea.l CurrentA5,A5
//};
//DrawHackCont();
// *************************************************************
// Ditch the window ? or leave it around... TBD
if ( 0) {
while (!Button())
;
SetPort( savPort);
DisposeWindow( thWinPtr);
DisposeHandle( wdefHdl);
}
//SetPort( savPort);
}
#if(0)
// *************************************************************
// Old way. Make a Ptr, stuff the WDEF, make a handle,
// stuff a JMP and Ptr address (don't ask me, I made it work!)
wdefProcPtr = NewPtr(procSize);
BlockMove( (Ptr)HackWindow, wdefProcPtr, procSize);
wdefHdl = NewHandle (sizeof(**wdefHdl));
(**wdefHdl).jmp = 0x4EF9;
(**wdefHdl).addr = wdefProcPtr; //(**wdefHdl).addr = &HackWindow;
#endif
//*************************************************************************
// WDEF here. NEW_WINDOW is the nifty version, not NEW is an old
// wave version that works (!)
//*************************************************************************
#define kNoGrowVar 1
pascal long HackWindow( short varCode, WindowPeek theWindow, short message, long param)
{
Handle h, h2;
Boolean growable;
Rect r, bitsR;
Point pt;
long dataSize;
CGrafPtr cGrafPtr;
GrafPtr savPort;
RGBColor tC;
Pattern blk = { 0,0,0,0,0,0,0,0};
Pattern wht = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
Pattern gr = { 0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55};
growable = (varCode != kNoGrowVar);
switch (message) {
case wDraw:
// ************************************************************
// DRAW
// check the visible flag. If not visible, forget it!
if ( !theWindow->visible)
return;
// ************************************************************
// Next, check the value of param
//
// 0 Draw entire window frame
// check hilite
// check goAway flag in window record
// check growable flag
// 4 Handle goAway
//
// Note that drawing is clipped to the structure rgn
//
if ( param == 4) {
// no go away right now
break;
}
#if(NEW_WINDOW)
//PenPat( gr);
GetPort( &savPort);
GetCWMgrPort( &cGrafPtr); // Most Necessary to draw in color
SetPort( cGrafPtr);
PenNormal();
tC.red = Random(); //0x4400;
tC.green = 0x0000;
tC.blue = 0x0000;
RGBForeColor( &tC);
PaintRgn( theWindow->strucRgn);
ForeColor( blackColor);
FrameRgn( theWindow->strucRgn);
FrameRect( &(**theWindow->contRgn).rgnBBox);
BackColor( whiteColor);
EraseRgn( theWindow->contRgn);
if ( theWindow->hilited) {
Rect r;
short hL;
short curPen;
long indC[ 20] = {0,1,2,3,4,5,6,12,18,24,30,215,71,218,220,221,222,223,255};
short *clutPtr; // ditch the type stuff
// interesting indexes in the system clut
// 0,1,2,3,4,5,6,12,18,24,30,215,71,218,220,221,222,223,255
//DebugStr("\p;thecport");
//tC.red = 0x4400;
//tC.green = 0x0000;
//tC.blue = 0x0000;
//RGBForeColor( &tC);
//PaintRgn( theWindow->strucRgn);
// ********************************************************
// We want to draw in nice colors. Index2Color() FAILS
// So we get the colors directly from the system CLUT.
// FOUR shorts to each colorSpec
if(0) {
r = (**theWindow->strucRgn).rgnBBox;
curPen = 2;
PenSize( curPen, curPen);
clutPtr = &(**(**cGrafPtr->portPixMap).pmTable).ctTable;
Debugger();
for( hL=0; hL<20; hL++) {
Index2Color( indC[hL], &tC);
//tC.red = clutPtr[ indC[hL]+1];
//tC.green = clutPtr[ indC[hL]+2];
//tC.blue = clutPtr[ indC[hL]+3];
RGBForeColor( &tC);
MoveTo( r.left+4, r.top+58+hL*curPen);
Line( r.right-r.left-8, 0);
MoveTo( r.left+4, r.top+58-hL*curPen);
Line( r.right-r.left-8, 0);
}
//PenMode( patBic);
//h2 = NewHandle( 0);
//HandAndHand( theWindow->strucRgn, h2);
//InsetRgn( (RgnHandle)h2, -2, -2);
//PaintRgn( (RgnHandle)h2);
}
} else if ( growable) {
}
#else
r = (**theWindow->strucRgn).rgnBBox;
FrameRect( &r);
#endif
ForeColor( blackColor);
PenNormal();
SetPort( savPort);
break;
case wHit:
// ************************************************************
// HIT
pt.v = (param & 0xFFFF0000) >> 0x10;
pt.h = param & 0x0000FFFF;
GlobalToLocal( &pt);
if ( pt.v < kWinHdrHt)
return wInDrag;
//Debugger();
if ( PtInRgn( pt, theWindow->contRgn))
return wInContent;
return wInGrow;
return wNoHit;
break;
case wCalcRgns:
// ************************************************************
// CALC REGIONS
dataSize = (long)((Ptr)endData - (Ptr)dataProc);
h = NewHandle( dataSize);
BlockMove( (Ptr)dataProc, *h, dataSize);
r = theWindow->port.portRect;
if ( (*(CWindowRecord*)theWindow).port.portVersion < 0)
bitsR = (**(*(CWindowRecord*)theWindow).port.portPixMap).bounds;
else
bitsR = theWindow->port.portBits.bounds;
DisposeRgn( theWindow->strucRgn);
OffsetRgn( (RgnHandle)h, -bitsR.left, -bitsR.top);
theWindow->strucRgn = (RgnHandle)h;
OffsetRect( &r, -bitsR.left, -bitsR.top);
r.top += kWinHdrHt;
r.left += 3;
r.right -= 2;
r.bottom -= 2;
OpenRgn();
FrameRect(&r);
CloseRgn( theWindow->contRgn);
break;
case wNew:
// ************************************************************
// NEW
break;
case wDispose:
// ************************************************************
// DISPOSE
break;
case wGrow:
// ************************************************************
// GROW
if ( growable) {
;
}
break;
case wDrawGIcon:
// ************************************************************
// DRAW GROW ICON
break;
default:
break;
};
}
/********************************************************************************
dataProc
*********************************************************************************/
void dataProc()
{
asm {
dc.w 0x0824,0x0000,0x0000,0x005F,0x01F7,0x0000
dc.w 0x00CA,0x00D4,0x0117,0x011D,0x7FFF,0x0001
dc.w 0x00C3,0x00CA,0x00D4,0x00DA,0x010E,0x0117
dc.w 0x011D,0x0126,0x7FFF,0x0002,0x00C0,0x00C3
dc.w 0x00DA,0x00DE,0x010A,0x010E,0x0126,0x0129
dc.w 0x7FFF,0x0003,0x00BC,0x00C0,0x00DE,0x00E1
dc.w 0x0107,0x010A,0x0129,0x012C,0x7FFF,0x0004
dc.w 0x00BB,0x00BC,0x00E1,0x00E3,0x0104,0x0107
dc.w 0x012C,0x012E,0x7FFF,0x0005,0x00B9,0x00BB
dc.w 0x00E3,0x00E5,0x0102,0x0104,0x012E,0x0130
dc.w 0x7FFF,0x0006,0x00B7,0x00B9,0x00E5,0x00E7
dc.w 0x0100,0x0102,0x0130,0x0132,0x7FFF,0x0007
dc.w 0x00B5,0x00B7,0x00E7,0x00E8,0x00FE,0x0100
dc.w 0x0132,0x0133,0x7FFF,0x0008,0x00B4,0x00B5
dc.w 0x00E8,0x00E9,0x00FD,0x00FE,0x0133,0x0134
dc.w 0x7FFF,0x0009,0x00B3,0x00B4,0x00E9,0x00EA
dc.w 0x00FB,0x00FD,0x0134,0x0135,0x7FFF,0x000A
dc.w 0x00B2,0x00B3,0x00EA,0x00EC,0x00FA,0x00FB
dc.w 0x0135,0x0136,0x7FFF,0x000B,0x00B1,0x00B2
dc.w 0x00F9,0x00FA,0x0136,0x0137,0x7FFF,0x000C
dc.w 0x00B0,0x00B1,0x00CC,0x00D1,0x00EC,0x00ED
dc.w 0x00F7,0x00F9,0x0137,0x0138,0x7FFF,0x000D
dc.w 0x00CA,0x00CC,0x00D1,0x00D3,0x00ED,0x00EE
dc.w 0x00F7,0x00F8,0x7FFF,0x000E,0x00AF,0x00B0
dc.w 0x00C9,0x00CA,0x00D3,0x00D4,0x00EE,0x00EF
dc.w 0x00F8,0x00F9,0x0138,0x0139,0x7FFF,0x000F
dc.w 0x00AE,0x00AF,0x00C8,0x00C9,0x00D4,0x00D6
dc.w 0x00EF,0x00F0,0x7FFF,0x0010,0x00AD,0x00AE
dc.w 0x00C7,0x00C8,0x00D6,0x00D7,0x00F9,0x00FA
dc.w 0x0139,0x013A,0x7FFF,0x0011,0x00F0,0x00F1
dc.w 0x00FA,0x00FB,0x010F,0x0117,0x7FFF,0x0012
dc.w 0x00AC,0x00AD,0x00C6,0x00C7,0x00D7,0x00D8
dc.w 0x010D,0x010F,0x0117,0x011A,0x7FFF,0x0013
dc.w 0x00F1,0x00F2,0x00FB,0x00FC,0x010A,0x010D
dc.w 0x011A,0x011B,0x7FFF,0x0014,0x00AB,0x00AC
dc.w 0x00D8,0x00D9,0x00FC,0x00FD,0x0108,0x010A
dc.w 0x011B,0x011C,0x7FFF,0x0015,0x00C5,0x00C6
dc.w 0x00F2,0x00F3,0x0107,0x0108,0x011C,0x011D
dc.w 0x013A,0x013B,0x7FFF,0x0016,0x00FD,0x00FE
dc.w 0x0105,0x0107,0x7FFF,0x0017,0x00AA,0x00AB
dc.w 0x00FE,0x00FF,0x0103,0x0105,0x011D,0x011E
dc.w 0x7FFF,0x0018,0x00C4,0x00C5,0x00F3,0x00F4
dc.w 0x0102,0x0103,0x7FFF,0x0019,0x00D9,0x00DA
dc.w 0x00FF,0x0102,0x7FFF,0x001A,0x013A,0x013B
dc.w 0x7FFF,0x001B,0x00A9,0x00AA,0x7FFF,0x001D
dc.w 0x00F4,0x00F5,0x7FFF,0x001F,0x011D,0x011E
dc.w 0x7FFF,0x0020,0x0139,0x013A,0x7FFF,0x0021
dc.w 0x0000,0x00A9,0x00C4,0x00DA,0x00F5,0x011D
dc.w 0x0139,0x01F7,0x7FFF,0x0022,0x0001,0x00A9
dc.w 0x00C4,0x00DA,0x00F5,0x011C,0x0138,0x01F6
dc.w 0x7FFF,0x0023,0x0002,0x00A9,0x00C4,0x00DA
dc.w 0x00F5,0x011C,0x0138,0x01F5,0x7FFF,0x0025
dc.w 0x0004,0x00AA,0x00C5,0x00D9,0x00F4,0x011B
dc.w 0x0137,0x01F3,0x7FFF,0x0026,0x00C5,0x00C6
dc.w 0x011A,0x011B,0x7FFF,0x0027,0x00AA,0x00AB
dc.w 0x00D8,0x00D9,0x0136,0x0137,0x7FFF,0x0028
dc.w 0x0119,0x011A,0x0135,0x0136,0x7FFF,0x0029
dc.w 0x00C6,0x00C7,0x00D7,0x00D8,0x0118,0x0119
dc.w 0x7FFF,0x002A,0x00AB,0x00AC,0x00C7,0x00C8
dc.w 0x0134,0x0135,0x7FFF,0x002B,0x00AC,0x00AD
dc.w 0x00C8,0x00C9,0x00D6,0x00D7,0x0117,0x0118
dc.w 0x0133,0x0134,0x7FFF,0x002C,0x00C9,0x00CA
dc.w 0x00D4,0x00D6,0x00F3,0x00F4,0x0116,0x0117
dc.w 0x7FFF,0x002D,0x00AD,0x00AE,0x00CA,0x00CD
dc.w 0x00D1,0x00D4,0x0132,0x0133,0x7FFF,0x002E
dc.w 0x00AE,0x00AF,0x00CD,0x00D1,0x0115,0x0116
dc.w 0x0131,0x0132,0x7FFF,0x002F,0x00AF,0x00B0
dc.w 0x00F2,0x00F3,0x0114,0x0115,0x0130,0x0131
dc.w 0x7FFF,0x0030,0x00B0,0x00B1,0x0113,0x0114
dc.w 0x7FFF,0x0031,0x00B1,0x00B2,0x0112,0x0113
dc.w 0x012F,0x0130,0x7FFF,0x0032,0x0070,0x0077
dc.w 0x007E,0x0085,0x008D,0x0092,0x009F,0x00A3
dc.w 0x00B2,0x00B3,0x00F1,0x00F2,0x0111,0x0112
dc.w 0x012E,0x012F,0x0141,0x0146,0x014C,0x0151
dc.w 0x0158,0x015D,0x016A,0x016E,0x0173,0x0178
dc.w 0x017C,0x017E,0x7FFF,0x0033,0x0077,0x0078
dc.w 0x009C,0x009F,0x00A3,0x00A6,0x00B3,0x00B5
dc.w 0x012D,0x012E,0x0167,0x016A,0x016E,0x0171
dc.w 0x017B,0x017C,0x017E,0x0181,0x7FFF,0x0034
dc.w 0x007D,0x007E,0x0092,0x0093,0x009B,0x009C
dc.w 0x00A5,0x00A6,0x00B5,0x00B6,0x00F0,0x00F1
dc.w 0x0110,0x0111,0x012C,0x012D,0x015D,0x015E
dc.w 0x0166,0x0167,0x0170,0x0171,0x0180,0x0181
dc.w 0x7FFF,0x0035,0x008C,0x008D,0x009A,0x009B
dc.w 0x00B6,0x00B8,0x010F,0x0110,0x012B,0x012C
dc.w 0x0157,0x0158,0x0165,0x0166,0x017A,0x017B
dc.w 0x017F,0x0180,0x7FFF,0x0036,0x0078,0x0079
dc.w 0x0099,0x009A,0x009F,0x00A5,0x00B8,0x00BB
dc.w 0x00EF,0x00F0,0x010E,0x010F,0x012A,0x012B
dc.w 0x0164,0x0165,0x016A,0x0170,0x017E,0x017F
dc.w 0x7FFF,0x0037,0x007C,0x007D,0x0093,0x0094
dc.w 0x009E,0x009F,0x00BB,0x00BE,0x010D,0x010E
dc.w 0x0129,0x012A,0x015E,0x015F,0x0169,0x016A
dc.w 0x0179,0x017A,0x7FFF,0x0038,0x008B,0x008C
dc.w 0x008E,0x0090,0x0098,0x0099,0x009D,0x009E
dc.w 0x00BE,0x00C2,0x00D0,0x00D4,0x00EE,0x00EF
dc.w 0x010C,0x010D,0x0128,0x0129,0x0146,0x014C
dc.w 0x0156,0x0157,0x0159,0x015B,0x0163,0x0164
dc.w 0x0168,0x0169,0x0178,0x0179,0x017D,0x017E
dc.w 0x7FFF,0x0039,0x0074,0x0075,0x0079,0x007A
dc.w 0x007F,0x0080,0x00C2,0x00D0,0x010B,0x010C
dc.w 0x017C,0x017D,0x7FFF,0x003A,0x007B,0x007C
dc.w 0x008A,0x008B,0x0094,0x0095,0x00D3,0x00D4
dc.w 0x00ED,0x00EE,0x010A,0x010B,0x0127,0x0128
dc.w 0x0155,0x0156,0x015F,0x0160,0x017C,0x017D
dc.w 0x7FFF,0x003B,0x0075,0x0076,0x008D,0x008E
dc.w 0x0090,0x0091,0x00EC,0x00ED,0x0109,0x010A
dc.w 0x0126,0x0127,0x0146,0x014C,0x0158,0x0159
dc.w 0x015B,0x015C,0x017D,0x017E,0x7FFF,0x003C
dc.w 0x007A,0x007B,0x007E,0x007F,0x008D,0x0091
dc.w 0x0095,0x0096,0x0098,0x0099,0x00D2,0x00D3
dc.w 0x0108,0x0109,0x0125,0x0126,0x0158,0x015C
dc.w 0x0160,0x0161,0x0163,0x0164,0x0178,0x0179
dc.w 0x7FFF,0x003D,0x0089,0x008A,0x009D,0x009E
dc.w 0x00D1,0x00D2,0x00EB,0x00EC,0x0107,0x0108
dc.w 0x0124,0x0125,0x0154,0x0155,0x0168,0x0169
dc.w 0x0179,0x017A,0x017E,0x017F,0x7FFF,0x003E
dc.w 0x0076,0x0077,0x007D,0x007E,0x009E,0x009F
dc.w 0x00EA,0x00EB,0x0106,0x0107,0x0123,0x0124
dc.w 0x0169,0x016A,0x017F,0x0180,0x7FFF,0x003F
dc.w 0x0088,0x0089,0x008C,0x0092,0x0096,0x0097
dc.w 0x0099,0x009A,0x009F,0x00A5,0x00D0,0x00D1
dc.w 0x0105,0x0106,0x0122,0x0123,0x0153,0x0154
dc.w 0x0157,0x015D,0x0161,0x0162,0x0164,0x0165
dc.w 0x016A,0x0170,0x017A,0x017B,0x0180,0x0181
dc.w 0x7FFF,0x0040,0x009A,0x009B,0x00CF,0x00D0
dc.w 0x00E9,0x00EA,0x0104,0x0105,0x0121,0x0122
dc.w 0x0165,0x0166,0x7FFF,0x0041,0x0077,0x0078
dc.w 0x007C,0x007D,0x008B,0x008C,0x009B,0x009D
dc.w 0x00A5,0x00A6,0x00CE,0x00CF,0x00E8,0x00E9
dc.w 0x0103,0x0104,0x0120,0x0121,0x0156,0x0157
dc.w 0x0166,0x0168,0x0170,0x0171,0x017B,0x017C
dc.w 0x0181,0x0182,0x7FFF,0x0042,0x0087,0x0088
dc.w 0x0092,0x0093,0x0097,0x0098,0x009D,0x00A0
dc.w 0x00A4,0x00A6,0x00CD,0x00CE,0x00E7,0x00E8
dc.w 0x0102,0x0103,0x011F,0x0120,0x0152,0x0153
dc.w 0x015D,0x015E,0x0162,0x0163,0x0168,0x016B
dc.w 0x016F,0x0171,0x017C,0x017D,0x017F,0x0182
dc.w 0x7FFF,0x0043,0x0070,0x0074,0x0078,0x007C
dc.w 0x0080,0x0085,0x0087,0x008B,0x0093,0x0098
dc.w 0x00A0,0x00A4,0x00CC,0x00CD,0x00E6,0x00E7
dc.w 0x0101,0x0102,0x011E,0x011F,0x0141,0x0146
dc.w 0x014C,0x0151,0x0152,0x0156,0x015E,0x0163
dc.w 0x016B,0x016F,0x0173,0x0178,0x017D,0x017F
dc.w 0x7FFF,0x0044,0x00CB,0x00CC,0x00E5,0x00E6
dc.w 0x0100,0x0101,0x011D,0x011E,0x7FFF,0x0045
dc.w 0x00CA,0x00CB,0x00E4,0x00E5,0x00FF,0x0100
dc.w 0x011C,0x011D,0x7FFF,0x0046,0x00C8,0x00CA
dc.w 0x00E3,0x00E4,0x00FE,0x00FF,0x011B,0x011C
dc.w 0x7FFF,0x0047,0x00C7,0x00C8,0x00E2,0x00E3
dc.w 0x00FD,0x00FE,0x011A,0x011B,0x7FFF,0x0048
dc.w 0x00C5,0x00C7,0x00E1,0x00E2,0x00FC,0x00FD
dc.w 0x0119,0x011A,0x7FFF,0x0049,0x00C4,0x00C5
dc.w 0x00E0,0x00E1,0x00FA,0x00FC,0x0119,0x013C
dc.w 0x7FFF,0x004A,0x00C2,0x00C4,0x00DF,0x00E0
dc.w 0x00F9,0x00FA,0x7FFF,0x004B,0x00C0,0x00C2
dc.w 0x00DE,0x00DF,0x00F8,0x00F9,0x7FFF,0x004C
dc.w 0x00BE,0x00C0,0x00DC,0x00DE,0x00F7,0x00F8
dc.w 0x7FFF,0x004D,0x00BC,0x00BE,0x00DB,0x00DC
dc.w 0x00F6,0x00F7,0x7FFF,0x004E,0x00B9,0x00BC
dc.w 0x00D9,0x00DB,0x00F5,0x00F6,0x7FFF,0x004F
dc.w 0x00B5,0x00B9,0x00D8,0x00D9,0x00F4,0x00F5
dc.w 0x7FFF,0x0050,0x00B1,0x00B5,0x00D7,0x00D8
dc.w 0x7FFF,0x0051,0x00D5,0x00D7,0x7FFF,0x0052
dc.w 0x00D3,0x00D5,0x7FFF,0x0053,0x00D1,0x00D3
dc.w 0x7FFF,0x0054,0x00CF,0x00D1,0x7FFF,0x0055
dc.w 0x00CD,0x00CF,0x7FFF,0x0056,0x00CB,0x00CD
dc.w 0x7FFF,0x0057,0x00C8,0x00CB,0x7FFF,0x0058
dc.w 0x00C5,0x00C8,0x7FFF,0x0059,0x00C2,0x00C5
dc.w 0x7FFF,0x005A,0x00BF,0x00C2,0x00F4,0x00F5
dc.w 0x7FFF,0x005B,0x0004,0x00B1,0x00BF,0x00F5
dc.w 0x013C,0x01F3,0x7FFF,0x005D,0x0002,0x01F5
dc.w 0x7FFF,0x005E,0x0001,0x01F6,0x7FFF,0x005F
dc.w 0x0000,0x01F7,0x7FFF,0x7FFF
};
}
void endData()
{
;
}
/********************************************************************************
MakeRgnBg
*********************************************************************************/
void MakeRgnBg()
{
PicHandle p;
RgnHandle r;
short resFileID;
Debugger();
p = (Handle)GetResource( 'PICT', 1024);
r = PICT2Rgn( p);
CreateResFile( "\ptemp");
resFileID = OpenResFile( "\ptemp");
AddResource( (Handle)r, 'tRgn', 1024, "\pwinBg");
WriteResource( (Handle)r);
CloseResFile( resFileID);
return;
}
/********************************************************************************
PICT2Rgn
Using a PicHandle, create the region (1 bit) described by the drawn PICT.
At present, make no adjustment for PICT frame.
Must work on a 68k !!
*********************************************************************************/
RgnHandle PICT2Rgn( PicHandle p )
{
GrafPtr aGP;
GrafPtr savPort;
Rect gpRect;
OSErr err;
BitMap *resBM;
RgnHandle rH;
if(!p) return 0;
gpRect = (**p).picFrame;
rH = NewRgn();
//if ( TrapAvailable( 0xA8D7)) {
if ( CreateOffscreenBitMap( &aGP, &gpRect ) ) {
//CheckAllocation( resBM=(BitMap*)NewPtr( sizeof(BitMap)));
resBM=(BitMap*)NewPtr( sizeof(BitMap));
GetPort( &savPort);
SetPort( aGP);
DrawPicture( p, &gpRect);
/* Bad news iff aGP is a color port */
*resBM = aGP->portBits;
if ( err = BitMapToRegion( rH, resBM)) {
DisposeRgn( rH );
rH = 0;
}
ClosePort( aGP);
DisposPtr( (Ptr)aGP);
//gError->CheckOSError( err = QDError());
DisposPtr( resBM->baseAddr);
DisposPtr( (Ptr)resBM);
SetPort( savPort);
} else {
DisposeRgn( rH);
rH = 0;
}
//} else {
// OpenRgn();
// FrameRect( &gpRect);
// CloseRgn( rH);
//}
return rH;
}
/********************************************************************************
PICT2BitMap
*********************************************************************************/
BitMap *PICT2BitMap( PicHandle p )
{
GrafPtr aGP;
GrafPtr savPort;
Rect gpRect;
BitMap *resBM;
if(!p) return 0;
resBM = (BitMap *)NewPtr( sizeof( BitMap ));
//CheckAllocation( resBM = (BitMap *)NewPtr( sizeof( BitMap ) ) );
gpRect = (**p).picFrame;
if ( CreateOffscreenBitMap( &aGP, &gpRect ) ) {
GetPort( &savPort ); SetPort( aGP );
DrawPicture( p, &gpRect );
/* Bad news iff really color port */
*resBM = aGP->portBits;
ClosePort(aGP);
DisposPtr((Ptr)aGP);
SetPort( savPort );
} else {
resBM->baseAddr = 0;
resBM->rowBytes = 0;
SetRect( &resBM->bounds, 0, 0, 0, 0 );
}
return resBM;
}
/********************************************************************************
CreateOffscreenBitMap
from DTS TechNote #41
*********************************************************************************/
Boolean CreateOffscreenBitMap(GrafPtr *newOffscreen, Rect *inBounds)
{
GrafPtr savePort;
GrafPtr newPort;
GetPort(&savePort); /* need this to restore thePort after OpenPort */
newPort = (GrafPtr) NewPtr(sizeof(GrafPort)); /* allocate the grafPort */
if (MemError() != noErr)
return false; /* failed to allocate the off-screen port */
/*
the call to OpenPort does the following . . .
allocates space for visRgn (set to screenBits.bounds)
and clipRgn (set wide open)
sets portBits to screenBits
sets portRect to screenBits.bounds
etc. (see IM I-163,164)
side effect: does a SetPort(&offScreen)
*/
OpenPort(newPort);
/* make bitmap the size of the bounds that caller supplied */
newPort->portRect = *inBounds;
newPort->portBits.bounds = *inBounds;
RectRgn(newPort->clipRgn, inBounds);/* avoid wide-open clipRgn, to be safe */
RectRgn(newPort->visRgn, inBounds); /* in case newBounds is > screen bounds */
/*rowBytes is size of row, it must be rounded up to an even number of bytes*/
newPort->portBits.rowBytes =
((inBounds->right - inBounds->left + 15) >> 4) << 1;
/* number of bytes in BitMap is rowBytes * number of rows */
/* see notes at end of Technical Note about using _NewHandle
rather than _NewPtr */
newPort->portBits.baseAddr =
NewPtr(newPort->portBits.rowBytes * (long)
(inBounds->bottom - inBounds->top));
if (MemError()!=noErr) { /* check to see if we had enough room for the bits */
SetPort(savePort);
ClosePort(newPort); /* dump the visRgn and clipRgn */
DisposPtr((Ptr)newPort); /* dump the GrafPort */
return false; /* tell caller we failed */
}
/* since the bits are just memory, let's clear them before we start */
EraseRect(inBounds); /* OpenPort did a SetPort(newPort) so we are ok */
*newOffscreen = newPort;
SetPort(savePort);
return true; /* tell caller we succeeded! */
}
/********************************************************************************
DestroyOffscreenBitMap
from DTS TechNote #41
*********************************************************************************/
void DestroyOffscreenBitMap(GrafPtr oldOffscreen)
{
ClosePort(oldOffscreen); /* dump the visRgn and clipRgn */
DisposPtr(oldOffscreen->portBits.baseAddr); /* dump the bits */
DisposPtr((Ptr)oldOffscreen); /* dump the port */
}
//**************************************************************************
// E N D O F L I S T I N G